package yt.demo.demoadmin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import yt.demo.appcommonbean.http.FileRequest;
import yt.demo.appcommonbean.http.RestResponse;
import yt.demo.appcommontools.utils.dto.FileInfoDTO;
import yt.demo.appcoresystem.service.IFileService;

@RestController
@RequestMapping("/file")
public class FileController extends BaseController {

    private final IFileService fileService;

    @Autowired
    public FileController(IFileService fileService) {
        this.fileService = fileService;
    }

    @PostMapping("/upload")
    public  RestResponse<FileInfoDTO> uploadFile(@RequestParam("file") MultipartFile file) {
        return RestResponse.ok(fileService.upload(file));
    }

    @PostMapping("/uploadBase64")
    public  RestResponse<FileInfoDTO> uploadBase64(@RequestBody FileRequest req) {
        return RestResponse.ok(fileService.uploadBase64(req.getBase64Data()));
    }



}
